package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.DlNewsCategoryDO;
import com.bootdo.system.service.DlNewsCategoryService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-06-04 15:09:00
 */
 
@Controller
@RequestMapping("/system/dlNewsCategory")
public class DlNewsCategoryController {
	@Autowired
	private DlNewsCategoryService dlNewsCategoryService;
	
	@GetMapping()
	@RequiresPermissions("system:dlNewsCategory:dlNewsCategory")
	String DlNewsCategory(){
	    return "system/dlNewsCategory/dlNewsCategory";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:dlNewsCategory:dlNewsCategory")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DlNewsCategoryDO> dlNewsCategoryList = dlNewsCategoryService.list(query);
		int count = dlNewsCategoryService.count(query);
		PageUtils pageUtils = new PageUtils(dlNewsCategoryList, count);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:dlNewsCategory:add")
	String add(){
	    return "system/dlNewsCategory/add";
	}

	@GetMapping("/edit/{newsCategoryId}")
	@RequiresPermissions("system:dlNewsCategory:edit")
	String edit(@PathVariable("newsCategoryId") Integer newsCategoryId,Model model){
		DlNewsCategoryDO dlNewsCategory = dlNewsCategoryService.get(newsCategoryId);
		model.addAttribute("dlNewsCategory", dlNewsCategory);
	    return "system/dlNewsCategory/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:dlNewsCategory:add")
	public R save( DlNewsCategoryDO dlNewsCategory){
		if(dlNewsCategoryService.save(dlNewsCategory)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:dlNewsCategory:edit")
	public R update( DlNewsCategoryDO dlNewsCategory){
		dlNewsCategoryService.update(dlNewsCategory);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:dlNewsCategory:remove")
	public R remove( Integer newsCategoryId){
		if(dlNewsCategoryService.remove(newsCategoryId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:dlNewsCategory:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] newsCategoryIds){
		dlNewsCategoryService.batchRemove(newsCategoryIds);
		return R.ok();
	}
	
}
